package com.supermali.system;

import com.supermali.creater.GameStarter;

public class SystemHelper {

    private SystemStatus systemStatus;

    private GameStarter gameStarter;

    private SystemStatus lastStatus;

    private AbstractSystem abstractSystem;
    // 关卡数
    int level = 1;

    public SystemHelper(GameStarter gameStarter) {
        this.gameStarter = gameStarter;
    }

    public AbstractSystem getAbstractSystem() {
        if(lastStatus!=systemStatus){
            // 需要加载xml文件
            if(systemStatus==SystemStatus.INDEX){
                lastStatus = systemStatus;
                gameStarter.clear();
                gameStarter.setPerson(1);
                // 图片加载完成后，初始化背景
                gameStarter.explainXml("/map.xml/Index.xml");
                this.abstractSystem = new IndexSystem(gameStarter,this);
            }else if(systemStatus==SystemStatus.LOADING){
                // 图片加载完成后，初始化背景
                lastStatus = systemStatus;
                gameStarter.clear();
                gameStarter.explainXml("/map.xml/Loading.xml");
                this.abstractSystem =  new LoadingSystem(gameStarter,this);
            }else if(systemStatus==SystemStatus.RUNNING){
                // 图片加载完成后，初始化背景
                lastStatus = systemStatus;
                gameStarter.clear();
                gameStarter.explainXml("/map.xml/"+level+".xml");
                gameStarter.setPerson(1);
                this.abstractSystem =  new RunningSystem(gameStarter,this);
            }
        }else {
            return this.abstractSystem;
        }

        return this.abstractSystem;
    }

    public void setSystemStatus(SystemStatus systemStatus) {
        this.systemStatus = systemStatus;
    }

    public void nextLevel(){
        level++;
        this.systemStatus = SystemStatus.LOADING;
    }
}
